Title

Subtitle

Stanford Doer School of Sustainability, Paleobiology Lab
Author
Affiliation
Published

2024-05-13

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

Code
1+1
[1] 2

You can add options to executable code like this (the option #| echo:false is used at the top of the code chunk).

The echo: false option disables the printing of code (only output is displayed), so the chunk is not visible.

Packages

Snippets of code using different languages can be included. Here we make a set of R packages available for usage in R code chunks:

Packages
pkgs <- "
DT bslib leaflet plotly htmltools dplyr purrr
"

import <- function(x)
 x |> trimws() |> strsplit("\\s+") |> unlist() |>
  lapply(function(x) library(x, character.only = TRUE)) |>
  invisible()

pkgs |> import()

Custom CSS - Logo example

A chunk used here includes a Stanford logo by generating a custom styles.css for the banner, which can be included in the quarto document.

Code
iuri <- knitr::image_uri(f = "_extensions/stanford-quarto/img/logo_text.png")

# htmltools::img(
#   src = iuri, 
#   alt = 'logo', 
#   style = 'position:absolute; top:0; right:0; padding:10px;',
#   height = '120px'
# )

styles_css <- 
".quarto-title-block .quarto-title-banner {
  background-image: url('%s');
  background-origin: content-box;
  background-size: 400px;
  background-position: right;
  background-position-y: bottom;
  background-repeat: no-repeat;
  padding-left: 10px;
  padding-right: 30px;
  padding-top: 30px;
  padding-bottom: 30 px;
}" |> sprintf(iuri)

message("Wrote background logo styles to styles.css")
Wrote background logo styles to styles.css
Code
readr::write_file(styles_css, "styles.css")

knitr::include_graphics(path = "_extensions/stanford-quarto/img/logo_text.png")

Plots

We can include static or dynamic plots, for example using ggplot.

This is an example of a static plot using Stanford graphical profile colors from Stanford Identity Guide.

This is an example of a interactive variant of the same plot.

More Information

You can learn more about controlling the appearance of HTML output here: https://quarto.org/docs/output-formats/html-basics.html